package net.tngou.iask.util;

import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.Date;

import org.ocpsoft.prettytime.PrettyTime;

public class Freemarker {

	
	/**
	 * 头像
	 * @return
	 */
	public String avatar(String avatar) {
		if(StringUtil.isNotEmpty(avatar))
			return StringUtil.replace(avatar, "/", "", 1);	
		return "common/avatar/default.png";
	}
	
	/**
	 * 时间格式
	 * @param time
	 * @return
	 */
	public String prettytime(Timestamp time) {
		PrettyTime p = new PrettyTime();
		return p.format(DateUtil.toDate(time.toLocalDateTime()));
	}
	
	public static String  Simple(String ID) {
		   String  simple="";
		   if(!ValidateTools.IDcard(ID))return simple;
		   switch (ID.length()) {
				case 15:
					simple=ID.substring(0,12)+"***";
					break;
			   case 18:
				   simple=ID.substring(0,14)+"****";
					break;
				default:
					break;
				}
		 
		  return simple;
	   }
	  /**
	   * 年龄
	   * @param birthday
	   * @return
	   */
	  public static int Age(java.sql.Date birthday)
	  {
		  return LocalDate.now().getYear()-birthday.toLocalDate().getYear();
	  }
}
